﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Crosland.Automotriz.Core;
namespace Crosland.Automotriz.Data.Dao.Linq
{
    public class clsT_MaterialPorAsignarDAO
    {
        AutomotrizEntities ContextoDeObjs = new AutomotrizEntities();


        public bool Insertar(T_MATERIAL_POR_ASIGNAR Obj)
        {
            try
            {
                ContextoDeObjs.AddObject("T_MATERIAL_POR_ASIGNAR", Obj);
                ContextoDeObjs.SaveChanges();

            }
            catch (Exception)
            {
                return false;
            }
            return true;
        }
        public Boolean Modificar(T_MATERIAL_POR_ASIGNAR Obj)
        {
            try
            {
                ContextoDeObjs.AddObject("T_MATERIAL_POR_ASIGNAR", Obj);
                ContextoDeObjs.ObjectStateManager.ChangeObjectState(Obj, System.Data.EntityState.Modified);
                ContextoDeObjs.SaveChanges();
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }
        public Boolean ActualizarIndAsignado(int intIDMaterial)
        {
            try
            {
                ContextoDeObjs.ExecuteStoreCommand(String.Format("UPDATE T_MATERIAL_POR_ASIGNAR SET IND_ASIGNADO = 1 where ID_MATERIAL = {0}", intIDMaterial));
                return true;
            }
            catch (Exception)
            {
                return false;
            }
        }


        public bool ActualizaTMaterialPorAsignar(int intIdGrupoArticulo,int intIdSector,int intIdJerarquia,int intIdModelo,String strCodigo) {

            try
            {
                ContextoDeObjs.ExecuteStoreCommand(String.Format("UPDATE T_MATERIAL_POR_ASIGNAR SET ID_GRUPO_ARTICULO ={0},ID_SECTOR ={1},ID_JERARQUIA ={2},ID_MODELO ={3},IND_ASIGNADO =1 WHERE COD_MATERIAL='{4}' AND IND_ASIGNADO=0", intIdGrupoArticulo, intIdSector, intIdJerarquia, intIdModelo, strCodigo));
                return true;
            }
            catch (Exception)
            {
                
               return false;
            }
        
        }

        public bool ActualizaCodMaterial(String COD_MATERIAL, int ID_MATERIAL)
        {
            ContextoDeObjs.ExecuteStoreCommand(String.Format("UPDATE T_MATERIAL_POR_ASIGNAR SET	COD_MATERIAL ='{0}' WHERE ID_MATERIAL={1}", COD_MATERIAL, ID_MATERIAL));
            return true;
        }

        public bool ActualizaIdGrupoArticulos(String COD_MATERIAL, int ID_GRUPO_ARTICULO, int ID_MATERIAL)
        {
            ContextoDeObjs.ExecuteStoreCommand(String.Format("UPDATE T_MATERIAL_POR_ASIGNAR SET	COD_MATERIAL ='{0}',ID_GRUPO_ARTICULO ={1} WHERE ID_MATERIAL={2}", COD_MATERIAL, ID_GRUPO_ARTICULO, ID_MATERIAL));
            return true;
        }
        public bool ActualizaIdSector(String COD_MATERIAL, int ID_SECTOR, int ID_MATERIAL)
        {
            ContextoDeObjs.ExecuteStoreCommand(String.Format("UPDATE T_MATERIAL_POR_ASIGNAR SET	COD_MATERIAL ='{0}',ID_SECTOR ={1} WHERE ID_MATERIAL={2}", COD_MATERIAL, ID_SECTOR, ID_MATERIAL));
            return true;
        }
        public bool ActualizaIdJerarquia(String COD_MATERIAL, int ID_JERARQUIA, int ID_MATERIAL)
        {
            ContextoDeObjs.ExecuteStoreCommand(String.Format("UPDATE T_MATERIAL_POR_ASIGNAR SET	COD_MATERIAL ='{0}',ID_JERARQUIA ={1} WHERE ID_MATERIAL={2}", COD_MATERIAL, ID_JERARQUIA, ID_MATERIAL));
            return true;
        }

        public bool ActualizaIdModelo(String COD_MATERIAL, int ID_MODELO, int ID_MATERIAL)
        {
            ContextoDeObjs.ExecuteStoreCommand(String.Format("UPDATE T_MATERIAL_POR_ASIGNAR SET	COD_MATERIAL ='{0}',ID_MODELO ={1} WHERE ID_MATERIAL={2}", COD_MATERIAL, ID_MODELO, ID_MATERIAL));
            return true;
        }

    }
}
